<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公文处理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>公文标题：</label>
                                <input type="text" name="arrangeTitle"/>
                            </li>
                            <li>
                                <label>发起人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>发起机构：</label>
                                <input type="text" name="deptName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('document_progress_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('document:progress:edit')}]];
        var removeFlag = [[${@permission.hasPermi('document:progress:remove')}]];
        var receiveFlag = [[${@permission.hasPermi('document:progress:receive')}]];
        var statusDatas = [[${@dict.getType('document_progress_status')}]];
        var prefix = ctx + "document/progress";

        $(function() {
            var options = {
                url: prefix + "/list",
                removeUrl: prefix + "/remove",
                modalName: "公文处理",
                sortName: "updateTime",
		        sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'progressId',
                    title: '公文处理ID',
                    visible: false
                },
                {
                    field: 'arrangeTitle',
                    title: '公文标题'
                },
                {
                    field: 'status',
                    title: '处理状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'userName',
                    title: '发起人'
                },
                {
                    field: 'deptName',
                    title: '发起机构'
                },
                {
                    field: 'receiveDate',
                    title: '接收日期'
                },
                {
                    field: 'endDate',
                    title: '截止日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if("1"==row.status){
                            actions.push('<a class="btn btn-success btn-xs ' + receiveFlag + '" href="javascript:void(0)" onclick="receive(\'' + row.progressId + '\',' + row.receiptTips + ')"><i class="fa fa-edit"></i>接收</a> ');
                        } else if("2" == row.status) {
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="view_detail(\'' + row.arrangeId + "&" + row.arrangeTitle + '\')"><i class="fa fa-search"></i>详情</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function post_receive(progressId,receiptInfo){
            var url = prefix+"/receive"
            $.ajax({
				cache : false,
				type : "post",
				url : url,
				data : {
                    "progressId": progressId,
                    "receiptInfo": receiptInfo,
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
        }

        function receive(progressId,receiptTips){
            let receiptInfo = "";
            if("1"==receiptTips){
                layer.prompt({
                    title: '填写回执信息',
                    formType: 2
                }, 
                function(text, index){
                    layer.close();
                    receiptInfo = text;
                    post_receive(progressId,receiptInfo);
                });
            }else{
                post_receive(progressId,receiptInfo);
            }
        }

        function view_detail(arrangeId ){
            // console.log("标题:" + arrangeId);
            var split = arrangeId.split("&");
            var url = prefix + "/detail/" + Number(split[0])

            $.modal.openTab("详情展示",url);
        }

    </script>
</body>
</html>